# -*- coding: utf-8 -*-
"""
Created on Sat Nov 13 21:25:52 2021

@author: 刘长奇-2019300677
"""
import numpy as np
import matplotlib.pyplot as plt
num,q1,q2,q3,q4,q5,q6,q7,q8,q9,q10,q11,q12,q13,q14,q15,q16,q17,q18,q19,q20,q21,q22,q23,q24,q25,q26,q27,q28,q29,q30,q31,q32,q33,q34,q35,q36,y= np.loadtxt("train.csv",delimiter=',', usecols=(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37), 
	unpack=True)
num = num.reshape(-1,1)
y = y.reshape(-1,1)
for i in range(1,37):
    exec ("q%s=q%s.reshape(-1,1)"%(i,i))
train = np.hstack((q1.reshape(-1,1),q2.reshape(-1,1)))
for i in range(3,37):
    exec ("train=np.hstack((train,q%s.reshape(-1,1)))"%i)
#产生训练集

from sklearn.neural_network import MLPClassifier
clf_class= MLPClassifier(solver='adam', alpha=1e-5,hidden_layer_sizes=(40,20), random_state=1,max_iter=1500)
clf_class.fit(train,y)
#sklearn神经网络学习，隐藏层两层，第一层40个节点，第二层20个节点，最多迭代1500次

y_pred=[]
j=0
for i in range(np.shape(train)[0]):
    y_pred.append(clf_class.predict([train[i]]))
for i in range(np.shape(train)[0]):
    if y_pred[i]==y[i]:
        j=j+1
    if (i+1)%200==0:
        print(j/200000)
#训练集准确率计算：0.925

from sklearn.metrics import confusion_matrix
import seaborn as sns
y_pred=np.array(y_pred)
confusion_matrix_result=confusion_matrix(y,y_pred)
plt.figure(figsize=(10,6))
sns.heatmap(confusion_matrix_result,annot=True,cmap='Blues')
plt.xlabel('Predicted labels')
plt.ylabel('True labels')
plt.show()
#混淆矩阵将错误数据可视化




